package br.edu.fasete.javaroad.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class EntityList {
	private List<EntityDescriptor> classes;
	
	public EntityList() {
		classes = new ArrayList<EntityDescriptor>();
	}
	
	public List<EntityDescriptor> getClasses() {
		return classes;
	}
	
	public void setClasses(List<EntityDescriptor> classes) {
		this.classes = classes;
	}

	public void addClass(EntityDescriptor c) {
		classes.add(c);
	}
	
	public void removeClass(EntityDescriptor c) {
		classes.remove(c);
	}
	
	public EntityDescriptor findEntity(String name) {
		EntityDescriptor ret = null;
		Iterator<EntityDescriptor> it = classes.iterator();
		while(it.hasNext()) {
			EntityDescriptor temp = it.next();
			if(temp.getName().equalsIgnoreCase(name)) {
				ret = temp;
				break;
			}
		}
		return ret;
	}
	
	public ClassDescriptor findClass(String name) {
		EntityDescriptor ret = findEntity(name);
		if(ret instanceof ClassDescriptor)
			return (ClassDescriptor) ret;
		else
			return null;
	}
	
	public InterfaceDescriptor findInterface(String name) {
		EntityDescriptor ret = findEntity(name);
		if(ret instanceof InterfaceDescriptor)
			return (InterfaceDescriptor) ret;
		else
			return null;
	}
	
	public Iterator<EntityDescriptor> iterator() {
		return classes.iterator();
	}
	
}
